﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace TetraEngine
{

    public class BlockGrid
    {
        int[,] grid;

        public BlockGrid(int size)
        {
            grid = new int[size, size];
        }
        public int this[int row, int column]
        {
            get { return grid[row, column]; }
            set { grid[row, column] = value; }
        }

        public int Size
        {
            get { return grid.GetLength(0); }
        }

        public void RotateCCW()
        {
            //Could someday replace with an in-place function
            int size = grid.GetLength(0);
            int[,] newGrid = new int[size, size];
            for (int i = 0; i < size; i++)
                for (int j = 0; j < size; j++)
                {
                    newGrid[i, j] = grid[j, size - (i + 1)];
                }
            grid = newGrid;
        }
        public void RotateCW()
        {
            //Could someday replace with an in-place function
            int size = grid.GetLength(0);
            int[,] newGrid = new int[size, size];
            for (int i = 0; i < size; i++)
                for (int j = 0; j < size; j++)
                {
                    newGrid[i, j] = grid[size - (j + 1), i];
                }
            grid = newGrid;
        }
        public override string ToString()
        {
            String s = "";
            int size = grid.GetLength(0);
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                    s += "[" + grid[i, j].ToString("00") + "]";
                s += "\n";
            }
            s = s.Remove(s.Length - 1, 1);
            return s;
        }

        public BlockGrid Copy()
        {
            int size = grid.GetLength(0);
            BlockGrid copy = new BlockGrid(size);
            for (int i = 0; i < size; i++)
                for (int j = 0; j < size; j++)
                    copy.grid[i, j] = this.grid[i, j];
            return copy;
        }

    }
}
